#include <stdio.h>
#include <stdlib.h>

typedef int data_t;
typedef struct linkqueue {
    int head;
    int tail;
    int size;
    int total;
    data_t data[];
} linkqueue_t;

linkqueue_t *create_linkqueue(int size) 
{
    linkqueue_t *lq;
    lq = malloc(sizeof(linkqueue_t) + (size + 1)* sizeof(int));
    lq->head = lq->tail = lq->total = 0;
    lq->size = size + 1;
    return lq;
}

int in_linkqueue(struct linkqueue *lq, int d) 
{
    if((lq->tail + 1) % lq->size == lq->head)
        return -1;
    lq->data[lq->tail] = d;
    lq->tail = (lq->tail + 1 / p->size;
    lq->total++;
    return 0;
}

void print_queue(linkqueue_t *lq) {
    int i;
    i = 0;
    while(lq->head + i < lq->tail) {
        printf("%d ", lq->data[lq->head + i]); 
        i++;
    }
    printf("\n");

}

/*
int out_linkqueue(struct linkqueue *lq) 
{
    dblink_t *dl;
    //如果头尾相等，则无数据
    if(lq->head == lq->tail) {
        return -1;
    } else {
        dl = lq->tail->from;
        lq->tail->from->next = NULL;
        lq->tail = lq->tail->from;
        return 0;
    }
}

int get_head_linkqueue(struct linkqueue *lq)
{
    return lq->head->next->data;
}

int is_empty_linkqueue()
{

}
*/

int main( int argc, const char *argv[]) 
{
    linkqueue_t *lq;
    int *d;
    lq = create_linkqueue(20);

    in_linkqueue(lq, 10);
    in_linkqueue(lq, 20);
    in_linkqueue(lq, 30);
    in_linkqueue(lq, 40);
    in_linkqueue(lq, 50);
    in_linkqueue(lq, 60);
    print_queue(lq);

    //in_linkqueue(lq, d);
    //printf("出队:%d\n", out_linkqueue(lq));
    return 0;
}

